new Vue({
    el:'#app',
    data: {
        goodslist:[],  //将从后端得到的数据存放在data中，以便于前端显示
        typelist:[],
        goodname:"",
        good_type:"",
        price_max:"",
        price_min:"",
        goodbrand:"",
        userid:"",
    },
    created(){
        this.userid = localStorage.getItem("user_id");
        console.log(this.userid);

        axios({
            method:'get', //post
            url: 'http://47.94.138.204:7790/goods/searchgoods',
            params:{
                // 得到的数据以json类型存放
            },
        }).then((res)=>{
            let result = res.data

            this.goodslist = result.data;
            console.log(this.goodslist);
        })


        axios({
            method:'get', //post
            url: 'http://47.94.138.204:7790/example/alltype',
            params:{
                // 得到的数据以json类型存放
            },
        }).then((res)=>{
            let result = res.data
            console.log("typelist")
            console.log(result)

            this.typelist = result;

        })
    },
    methods:{
        searchGoods:function (){
            let goodname = this.goodname;
            axios({
                method:'get', //post
                url: 'http://47.94.138.204:7790/example/alltype',
                params:{
                    // 得到的数据以json类型存放
                    goodname:goodname,
                },
            }).then((res)=>{
                let result = res.data
                console.log(result)
                this.typelist = result;


            })
        },
        toCart:function () {
            window.location.href = "shopping-cart.html";
        },
        personinfo:function (){
            window.open("userinfo.html?id=" + this.userid );
        },
        gooddetail:function (sid,eid){
            window.location.href = "goodsdetail.html?gid=" + sid + "&uid=6&sid="+eid;
        },
        findGoods:function () {

            if (this.goodname.replace(/(^\s*)|(\s*$)/g, "") == "")
            {
                alert("输入无效");
            }else{
                axios({
                    method:'get', //post
                    url: 'http://47.94.138.204:7790/goods/searchgoods',
                    params:{
                        // 得到的数据以json类型存放
                        name: this.goodname,
                    },
                }).then((res)=>{
                    let result = res.data;
                    this.searchList = result.data;
                    if(this.searchList.length > 0)
                    {
                        this.goodslist = this.searchList;
                        //window.location.href = "goodsdetail.html?gid=" + this.searchList[0].sid + "&uid=6&sid=" + this.searchList[0].eid;
                    }else{
                        alert("无相关商品");
                    }

                })
            }
        },
        screen:function ()
        {
            let obj = document.getElementById("good-type");
            var index = obj.selectedIndex; // 选中索引
            var value = obj.options[index].value; // 选中值

            console.log(value)
            axios({
                method:'get', //post
                url: 'http://47.94.138.204:7790/goods/screeninggoods',
                params:{
                    // 得到的数据以json类型存放
                    type:value,
                    brand:this.goodbrand,
                    min:this.price_min,
                    max:this.price_max
                },
            }).then((res)=>{
                let result = res.data;
                this.searchList = result.data;
                if(this.searchList.length > 0)
                {
                    this.goodslist = this.searchList;
                    //window.location.href = "goodsdetail.html?gid=" + this.searchList[0].sid + "&uid=6&sid=" + this.searchList[0].eid;
                }else{
                    alert("无相关商品");
                }

            })

        },
        reset:function ()
        {
            axios({
                method:'get', //post
                url: 'http://47.94.138.204:7790/goods/searchgoods',
                params:{
                    // 得到的数据以json类型存放
                },
            }).then((res)=>{
                let result = res.data

                this.goodslist = result.data;
                console.log(this.goodslist);
            })
        },
        quit:function ()
        {
            localStorage.setItem("user_id",'');
            window.location.href("searchgoods.html");
        },
        typegood: function ()
        {
            axios({
                method:'get', //post
                url: 'http://47.94.138.204:7790/goods/screeninggoods',
                params:{
                    // 得到的数据以json类型存放
                    type:"首饰",
                },
            }).then((res)=>{
                let result = res.data;
                this.searchList = result.data;
                if(this.searchList.length > 0)
                {
                    this.goodslist = this.searchList;
                    //window.location.href = "goodsdetail.html?gid=" + this.searchList[0].sid + "&uid=6&sid=" + this.searchList[0].eid;
                }else{
                    alert("无相关商品");
                }

            })

        },
        food: function ()
        {
            axios({
                method:'get', //post
                url: 'http://47.94.138.204:7790/goods/screeninggoods',
                params:{
                    // 得到的数据以json类型存放
                    type:"生鲜",
                },
            }).then((res)=>{
                let result = res.data;
                this.searchList = result.data;
                if(this.searchList.length > 0)
                {
                    this.goodslist = this.searchList;
                    //window.location.href = "goodsdetail.html?gid=" + this.searchList[0].sid + "&uid=6&sid=" + this.searchList[0].eid;
                }else{
                    alert("无相关商品");
                }

            })

        },
        iphone: function ()
        {
            axios({
                method:'get', //post
                url: 'http://47.94.138.204:7790/goods/screeninggoods',
                params:{
                    // 得到的数据以json类型存放
                    type:"数码产品",
                },
            }).then((res)=>{
                let result = res.data;
                this.searchList = result.data;
                if(this.searchList.length > 0)
                {
                    this.goodslist = this.searchList;
                    //window.location.href = "goodsdetail.html?gid=" + this.searchList[0].sid + "&uid=6&sid=" + this.searchList[0].eid;
                }else{
                    alert("无相关商品");
                }

            })

        },
        clothes: function ()
        {
            axios({
                method:'get', //post
                url: 'http://47.94.138.204:7790/goods/screeninggoods',
                params:{
                    // 得到的数据以json类型存放
                    type:"服装",
                },
            }).then((res)=>{
                let result = res.data;
                this.searchList = result.data;
                if(this.searchList.length > 0)
                {
                    this.goodslist = this.searchList;
                    //window.location.href = "goodsdetail.html?gid=" + this.searchList[0].sid + "&uid=6&sid=" + this.searchList[0].eid;
                }else{
                    alert("无相关商品");
                }

            })

        },
        shoes: function ()
        {
            axios({
                method:'get', //post
                url: 'http://47.94.138.204:7790/goods/screeninggoods',
                params:{
                    // 得到的数据以json类型存放
                    type:"鞋包",
                },
            }).then((res)=>{
                let result = res.data;
                this.searchList = result.data;
                if(this.searchList.length > 0)
                {
                    this.goodslist = this.searchList;
                    //window.location.href = "goodsdetail.html?gid=" + this.searchList[0].sid + "&uid=6&sid=" + this.searchList[0].eid;
                }else{
                    alert("无相关商品");
                }

            })

        },
        snacks: function ()
        {
            axios({
                method:'get', //post
                url: 'http://47.94.138.204:7790/goods/screeninggoods',
                params:{
                    // 得到的数据以json类型存放
                    type:"零食",
                },
            }).then((res)=>{
                let result = res.data;
                this.searchList = result.data;
                if(this.searchList.length > 0)
                {
                    this.goodslist = this.searchList;
                    //window.location.href = "goodsdetail.html?gid=" + this.searchList[0].sid + "&uid=6&sid=" + this.searchList[0].eid;
                }else{
                    alert("无相关商品");
                }

            })

        },

    },


})


var layer
$(function ()
{
    layui.use(['form'],function (args){
        layer=layui.layer;
    });
})
